<template>
	<!--扫码开票-->
	<view class="content">
		<view class="details-from">
			<form>
				<view class="uni-details-list">
					<view class="title">名称:</view>
					<view class="uni-input-01"><input name="input" placeholder="请输入名称" v-model="riseListPro.invoiceName" /></view>
				</view>
				<view class="uni-details-list">
					<view class="title">税号:</view>
					<view class="uni-input-01"><input name="input" placeholder="非必填" v-model="riseListPro.taxNo" /></view>
				</view>
				<view class="uni-details-list">
					<view class="title">企业地址:</view>
					<view class="uni-input-02"><input name="input" placeholder="非必填" v-model="riseListPro.address" /></view>
				</view>
				<view class="uni-details-list">
					<view class="title">企业电话:</view>
					<view class="uni-input-02"><input name="input" placeholder="非必填" v-model="riseListPro.phone" /></view>
				</view>
				<view class="uni-details-list">
					<view class="title">开户银行:</view>
					<view class="uni-input-02"><input name="input" placeholder="非必填" v-model="riseListPro.bankAccNo" /></view>
				</view>
				<view class="uni-details-list">
					<view class="title">开户账号:</view>
					<view class="uni-input-02"><input name="input" placeholder="非必填" v-model="riseListPro.bankNm" /></view>
				</view>
				<view class="uni-details-list">
					<view class="title">金额:</view>
					<view class="uni-input-01"><input name="input" placeholder="请输入金额" v-model="riseListPro.txnAmt" /></view>
				</view>
				<view class="ad-details">
					<view class="uni-details-list-content">
						<view class="title">内容:</view>
						<view class="uni-input-01">
							<textarea placeholder="请输入内容" v-model="riseListPro.content" class="riseListPro-content"/>
						</view>
						<view class="ad-billing-input">
							<!-- <button @click="addContent()" size="mini">编辑详细内容</button> -->
							<u-button type="primary" :plain="true" text="..." @click="addContent()"></u-button>
						</view>
					</view>
					
				</view>

				<view class="uni-details-list">
					<view class="title">备注:</view>
					<view class="uni-input-01">
						<textarea v-model="riseListPro.memo" placeholder="请输入内容" class="riseListPro-memo"></textarea>						
<!-- 						<input name="input" placeholder="请输入备注" v-model="riseListPro.memo" /> -->
					</view>
				</view>

				<view class="uni-details-list">
					<view class="title">商家:</view>
					<view class="uni-input-01"><input name="input" placeholder="请输入商家" v-model="merchant.merchantName" /></view>
				</view>

				<view class="uni-details-list">
					<view class="title">邮箱:</view>
					<view class="uni-input-01"><input name="input" placeholder="请输入邮箱" v-model="riseListPro.email" /></view>
				</view>

				<view class="ad-button"><button form-type="submit" @tap="keyword" class="button">提交</button></view>
			</form>
		</view>
	</view>
</template>
<script>
export default {
	data() {
		return {
			riseListPro: {
				taxNo: '',
				address: '',
				phone: '',
				bankNm: '',
				bankAccNo: '',
				email: '',
				invoiceName: '',
				txnAmt: '',
				content: '',
				memo: ''
			},
			merchant: {
				id: '',
				merchantName: ''
			}
		};
	},
	onLoad() {
		var me = this;
		this.riseListPro = uni.getStorageSync('riseListPro');
		console.log('riseListPros=' + JSON.stringify(this.riseListPro));
		var userinfo = uni.getStorageSync('user');
		console.log('content' + JSON.stringify(me.riseListPro.content));
		//打印数值
		console.log('user' + JSON.stringify(userinfo));
		uni.request({
			url: me.$ServerUrl + '/invoice/api/header/getDefaultHeaderByCustomerId', //通过客户ID获取默认抬头
			data: {
				customerId: userinfo.id
			},
			header: {
				'content-type': 'application/x-www-form-urlencoded' // 默认值JSON格式
			},
			method: 'GET',
			success(res) {
				console.log(res);
				console.log('------');
				console.log('------');
				if (!res.data) {
					uni.showModal({
						title: '提示',
						content: '开票失败，没有默认抬头',
						success: function(res) {
							if (res.confirm) {
								uni.switchTab({
									url: '../mine/index'
								});
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
								uni.switchTab({
									url: '../home/index'
								});
							}
						}
					});
				} else {
					me.riseListPro = res.data;
					me.riseListPro.invoiceName = res.data.name;
					me.riseListPro.taxNo = res.data.taxNo;
					me.riseListPro.address = res.data.address;
					me.riseListPro.phone = res.data.phone;
					me.riseListPro.bankNm = res.data.bankNm;
					me.riseListPro.email = res.data.email;
					me.riseListPro.txnAmt = res.data.txnAmt;
					me.riseListPro.bankAccNo = res.data.bankAccNo;
					console.log('UUU' + JSON.stringify(me.riseListPro));
					var rise = uni.getStorageSync('riseListPro');
					me.riseListPro.txnAmt = rise.txnAmt;
					me.riseListPro.memo = rise.memo;
					me.riseListPro.content = rise.content;
					//通过二维码内容获取二维码信息
					//获取缓存中二维码内容
					var content = uni.getStorageSync('content');
					console.log('content' + JSON.stringify(content));
					uni.request({
						url: me.$ServerUrl + '/invoice/api/qrcode/getMerchantIdByContent', //根据二维码内容二维码详情
						data: {
							content: content
						},
						header: {
							'content-type': 'application/json'
						},
						method: 'GET',
						success: res => {
							//获取二维码内容，获取商家ID
							// console.log(res.data.merchant.id)
							//商家ID
							var merchantId = res.data.merchant.id;
							//通过商家ID获取商家，
							uni.request({
								url: me.$ServerUrl + '/invoice/api/merchant/getMerchantById', //根据商家ID查询商家详情
								data: {
									id: merchantId
								},
								header: {
									'content-type': 'application/json'
								},
								method: 'GET',
								success: res => {
									//商家详情
									console.log('merchant:' + JSON.stringify(res));
									me.merchant.id = res.data.id;
									me.merchant.merchantName = res.data.merchantName;
								}
							});
						}
					});
				}
			}
		});
	},
	methods: {
		keyword(e) {
			var userinfo = uni.getStorageSync('user');
			//打印数值
			console.log('user' + JSON.stringify(userinfo));
			console.log(e);
			var me = this;
			console.log('-------111111111-----');
			console.log(me.riseListPro);
			// var Rise = this;
			uni.request({
				url: me.$ServerUrl + '/invoice/api/invoice/invoicing', //修改发票
				header: {
					'content-type': 'application/json' // 默认值
				},
				data: {
					merchant: {
						id: me.merchant.id //商家ID
					},
					customer: {
						id: userinfo.id //用户id
					},
					invoiceName: this.riseListPro.invoiceName,
					taxNo: this.riseListPro.taxNo,
					address: this.riseListPro.address,
					phone: this.riseListPro.phone,
					bankNm: this.riseListPro.bankNm,
					bankAccNo: this.riseListPro.bankAccNo,
					email: this.riseListPro.email,
					txnAmt: this.riseListPro.txnAmt,
					content: this.riseListPro.content,
					memo: this.riseListPro.memo
				},
				method: 'POST',
				success(res) {
					console.log(res);
					console.log('-------111111111-----');
					uni.removeStorage({
						key: 'riseListPro',
						success: function(res) {
							console.log('success');
						}
					});
					uni.showModal({
						content: '提交成功',
						showCancel: false,
						success() {
							uni.switchTab({
								url: '../home/index',
								success() {
									let page = getCurrentPages().pop(); //跳转页面成功之后
									if (!page) return;
									page.onLoad(); //如果页面存在，则重新刷新页面
								}
							});
						}
					});
				}
			});
		},
		addContent() {
			uni.setStorageSync('riseListPro', this.riseListPro);
			uni.redirectTo({
				url: '../../HelloWorld'
			});
		}
	}
};
</script>

<style>
page {
	width: 100%;
	height: 100%;
	background-color: #e1e5eb;
}

.content {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}

.details-from {
	width: 100%;
	height: 100%;
	padding: 10px;
}

.uni-details-list {
	border: 1px solid #ffffff;
	display: flex;
	background-color: #ffffff;
	align-items: center;
	padding: 10px;
	margin-bottom: 5px;
	border-radius: 10px;
	margin-left: 10px;
	margin-right: 10px;
}
.uni-details-list-content {
		border: 1px solid #ffffff;
		display: flex;
		background-color: #ffffff;
		align-items: center;
		padding: 10px;
		margin-bottom: 5px;
		border-radius: 10px;
		margin-left: 10px;
		margin-right: 10px;
		width: 100%;
	}
	.ad-details{
		display: flex;
		justify-content: center;
		align-items: center;
	}
.ad-text {
	margin-left: 10px;
}

.title {
	font-size: 14px;
	width: 65px;
}

.uni-input-01 {
	font-size: 14px;
	margin-left: 10px;
	width: 95%;
	overflow: auto;
}

.uni-input-01 input {
	width: 90%;
}

.uni-input-02 input {
	width: 90%;
}

.uni-input-02 {
	font-size: 14px;
	margin-left: 5px;
	width: 95%;
	overflow: auto;
}

.button {
	margin: 10px;
	color: #ffffff;
	background-color: #004fa3;
}

.swiths {
	margin-left: 10px;
}

.ad-billing-input {
}

.riseListPro-content {
	height: 40px;
	width: 95%;
}

.riseListPro-memo {
	height: 40px;
	width: 90%;
}
</style>
